/* eslint valid-jsdoc: "off" */

'use strict';

const path=require('path');

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1596554013067_9223';

  // add your middleware config here
  config.middleware = ['authException', 'errorHandler', 'jwtAuth'];

  config.jwtAuth = {
   ignore: ['/api/auth/login',],
  }

  config.security = {
    csrf: false,
    domainWhiteList: [ 'http://localhost:8080' ],
  }


  config.cors = {
    origin: '*', // 匹配规则  域名+端口  *则为全匹配
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  }
  
  config.multipart = {
    fileExtensions: [ '.apk', '.pptx', '.docx', '.csv', '.doc', '.ppt', '.pdf', '.pages', '.wav', '.mov' ], // 增加对 .apk 扩展名的支持
  }

  config.bcrypt = {
    saltRounds: 10 // default 10
  }
  
  config.passportJwt = {
    secret: '@@RTY2021##',
    expiresIn: '3600d'
    //ignore: '/', // optional
  }
  

  config.sequelize = {
    dialect: 'mysql',
    host: 'localhost',
    port: 3306,
    database: 'donghuang',
    username: 'root',
    password: '',
    exclude: 'index.js',
    // delegate: 'myModel',
    // baseDir: 'my_model',
    dialectOptions: {
      dateStrings: true,
      typeCast: true
    },
    timezone: '+08:00',
    define: {
      freezeTableName: true,
      underscored: true,
    },
  };

  config.cluster = {
    listen: {
      port: 7001,
      hostname: '0.0.0.0',
    }
  }

  config.static = {
    // maxAge: 31536000,
    dir: [
      {
        prefix: '/public/',
        dir: path.join(appInfo.baseDir, 'app/public')
      }, 
      { 
        prefix: '/web/', 
        dir: path.join(appInfo.baseDir, 'web')
      }
    ]
  };

  config.i18n = {
    defaultLocale: 'zh-CN',
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
